<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.all.js"></script>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

</head>
<body>
<form class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->


    <div class="layui-form-item">
        <label class="layui-form-label">维修记录id</label>
        <div class="layui-input-block">
            <input type="text" id="maintainRecordsId" name="maintainRecordsId" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">结算费用</label>
        <div class="layui-input-block">
            <input type="text" id="cost" name="cost" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户姓名</label>
        <div class="layui-input-block">
            <input type="text" name="customerName" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</form>
<script>

    $("#maintainRecordsId").val(localStorage.getItem("MaintainRecordsId"))

    layui.use('form', function () {
        var form = layui.form;
        form.on('submit(*)', function (data) {
            $.ajax({
                //请求方式nih
                type: "get",
                //请求的媒体类型
                contentType: "application/json;charset=UTF-8",
                dataType: "json",
                //请求地址
                data: data.field,
                url: "insert",
                success: function (result) {
                    alert("添加成功")
                }
            })
            console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });

</script>
</body>
</html>